// pages/class/class.js
Page({

      /**
       * 页面的初始数据
       */
      data: {

        classNum: 0,
        classInformation: []
      },
      //班级模块滑上显示
      slideOn() {
        console.log('1')
      },
      //成员管理
      groupManagement(e) {
        console.log(e)
        let classid = e.currentTarget.dataset.classid
        wx.navigateTo({
          url: '../class/groupManagement/groupManagement?classid=' + classid,
        })
      },

      //编辑班级
      editClass(e) {

        wx.navigateTo({
          url: '../class/joinClass/joinClass',
        })
      },
      //创建班级
      establishClass() {
        console.log('1')
        wx.navigateTo({
          url: '../class/establishClass/establishClass',
        })
      },
      //加入班级
      joinClass() {
        wx.navigateTo({
          url: '../class/joinClass/joinClass',
        })
      },
      //发布作业
      publishJob() {
        wx.navigateTo({
          url: '../class/publishJob/publishJob',
        })
      },
      //获取班级信息
      getClass() {
        const tid = wx.getStorageSync('tid') //获得教师的id
        wx.request({
          url: 'http://101.43.154.9:8001/askclass',
          method: 'POST',
          data: {
            cttid: tid
          },
          success: (res) => {
            console.log(res.data)
            console.log(res.data.length)
            if (res.data.length >= 1) {
              this.setData({
                classInformation: res.data,
                classNum: res.data.length
              })
            } else {
              this.setData({
                classInformation: [],
                classNum: 0
              })
            }
            // console.log(this.data.classInformation[0].cimg)
          }
        })
      },

      /**
       * 生命周期函数--监听页面加载
       */
      onLoad: function (options) {

      },

      /**
       * 生命周期函数--监听页面初次渲染完成
       */
      onReady: function () {

      },

      /**
       * 生命周期函数--监听页面显示
       */
      onShow: function () {

        if (typeof this.getTabBar === 'function' &&
          this.getTabBar()) {
          this.getTabBar().setData({
            selected: 0
          })
        }
        this.getClass()
      },

      /**
       * 生命周期函数--监听页面隐藏
       */
      onHide: function () {

      },

      /**
       * 生命周期函数--监听页面卸载
       */
      onUnload: function () {

      },

      /**
       * 页面相关事件处理函数--监听用户下拉动作
       */
      onPullDownRefresh: function () {

      },

      /**
       * 页面上拉触底事件的处理函数
       */
      onReachBottom: function () {

      },

      /**
       * 用户点击右上角分享
       */
      onShareAppMessage: function () {

      },
      //退出班级
      quitClass(e) {
        let that = this;
        let cid = e.currentTarget.dataset.id;
        console.log(cid)
        wx.showModal({
          title: '提示',
          content: '确定解散班级吗？',
          success(res) {
            if (res.confirm) {
              wx.request({
                url: 'http://101.43.154.9:8001/classdel',
                method: 'POST',
                data: {
                  cid: cid
                },
                success: (res) => {
                  if (res.data == "ok") {
                    wx.showToast({
                      title: '删除成功',
                      icon: "none"
                    })
                    that.getClass()
                  }
                },
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          },
        })
      },
      //邀请加入
      invitationClass(e) {
        let cid = e.currentTarget.dataset.id;
        wx.showModal({
          title: '提示',
          content: '班级邀请码是' + cid
        })
      }
    })